//
//  XRBaseSearchViewController.m
//  XClassRoom
//
//  Created by 余伟 on 2016/12/30.
//  Copyright © 2016年 Mr-yuwei. All rights reserved.
//

#import "XRBaseSearchViewController.h"

@interface XRBaseSearchViewController ()<UISearchBarDelegate>
{
  UISearchBar       *_searchbar;
}
@end

@implementation XRBaseSearchViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}
-(void)configOwnViews
{
    [super configOwnViews];
}
-(void)addOwnViews
{
    [super addOwnViews];
    [self addSearchBar];
}
-(void)addNavbarView
{
    [super addNavbarView];
}
- (void)addSearchBar
{
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,IPhone4_5_6_6P(200, 220, 250, 280), 30)];
//    UIColor *color =  self.navigationController.navigationBar.barTintColor;
//    [titleView setBackgroundColor:color];
    UISearchBar *searchBar = [[UISearchBar alloc] init];
    searchBar.delegate = self;
    searchBar.frame = CGRectMake(0, 0,IPhone4_5_6_6P(200, 220, 250, 280), 30);
   // searchBar.backgroundColor = color;
    searchBar.layer.cornerRadius = 15;
    searchBar.layer.masksToBounds = YES;
    [searchBar.layer setBorderWidth:8];
    [searchBar.layer setBorderColor:[UIColor whiteColor].CGColor];  //设置边框为白色
    searchBar.placeholder = self.searchPlaceholder?self.searchPlaceholder:@"请搜索你想要的东西";
;
    [titleView addSubview:searchBar];
    _searchbar=searchBar;
    [self.navigationItem.titleView sizeToFit];
    self.navigationItem.titleView = titleView;
}
#pragma mark UISearchBarDelegate
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    
    
}
- (UIImage*) GetImageWithColor:(UIColor*)color andHeight:(CGFloat)height
{
    CGRect r= CGRectMake(0.0f, 0.0f, 1.0f, height);
    UIGraphicsBeginImageContext(r.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, r);
    
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return img;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
